from microbit import *
from neopixel import NeoPixel

class neo16x16:
    def __init__(self, pin):
        self.np = NeoPixel(pin, 256)
        self.color = (0,0,8)

    def clear(self):
        self.np.clear()

    def set(self, n, dat):
        self.np[n] = dat
        self.np.show()

    def setcolor(self, color):
        self.color = color

    def show(self, dat, pos=0, clear = True, color=''):
        if color != '':
            self.color = color
        if clear:
            for i in range(256):
                self.np[i]=(0,0,0)
        for x in range(16):
            for y in range(16):
                if (x+pos)>=len(dat):
                    self.np[x*16+y]=(0,0,0)
                else:
                    if (1<<y)&dat[x+pos]:
                        if pos%2==0:
                            self.np[x*16 + y] = self.color
                        else:
                            self.np[x*16 +15 - y] = self.color
        self.np.show()

def _delay(t):
    while t>0:
        t = t - 1

npdat=[
0x0000,0x3E00,0x00C2,0x8100,0x0181,0x8100,0x0081,0x4300,
0x01BC,0x00C0,0x0600,0x0030,0x1800,0x000C,0x6000,0x0003,
0x0000,0x0000,0x0080,0x0382,0xFFE0,0xFFFF,0xFFFE,0x3DFF,
0xFFF8,0x071F,0x71F2,0xFE44,0x007F,0xF600,0x0007,0x0000,
0x0000,0x0000,0x00EC,0x7F80,0x41FE,0xFF82,0xE3FF,0xFFFE,
0x7FFF,0xFFFE,0xE3FF,0xFFC2,0x03FF,0x0FC0,0x00C0,0x0000,
0x6040,0x031E,0x4F00,0x03F0,0x07E0,0x07FC,0x3FE0,0x07FC,
0x1FE0,0x07F8,0x7FFC,0x7FF6,0x03FF,0xFFC0,0x0277,0x7878,
0x8000,0x0007,0x7000,0x001E,0x3E00,0x00F8,0x1F80,0x03F0,
0x07C0,0x73C0,0x01FE,0xFC00,0x003F,0xFC00,0x001E,0x7000,
0x0000,0x0600,0x00E0,0x0780,0x03F0,0x0FF0,0x1FE0,0x03FE,
0x1FC0,0x0078,0x08F0,0x3FE0,0x07FE,0x7FF0,0x07FF,0x79F0,
0x0000,0x03E0,0x1FF0,0x1FFC,0x7FF8,0x1FFF,0xFFF8,0x1FFF,
0xFFFC,0xFFFF,0xFFF9,0x1FFE,0x7FF0,0x0FFC,0x1FE0,0x0000,
0x0000,0x0000,0x1E00,0x00FE,0xF900,0x001F,0xFE00,0x00F7,
0xE3CC,0x3F8F,0x707F,0xFC00,0x003F,0xF400,0x0006,0x0000,
0x0000,0x0FC0,0x0FF8,0x39F8,0x3F0E,0xF0FC,0x7F9F,0xFFFE,
0x7FFF,0xFFFE,0x7F9F,0xF0FE,0x3F0E,0x39F8,0x0FF8,0x0FE0,
0x0000,0x03C0,0x0FF0,0x3FF8,0x3FFC,0x7CDC,0x779F,0xFCEE,
0x77FF,0xFCEE,0x779E,0x7CDC,0x3FFC,0x3FF8,0x0FF0,0x07C0,
0x0180,0x03FE,0xFF60,0x0C01,0xF818,0x3010,0x0806,0xC01F,
0x8003,0x60F9,0x910C,0x18F9,0x8030,0x06FF,0x7FC0,0x0180,
]

ne = neo16x16(pin1)
ne.setcolor((7,7,0))
n = 0
while True:
    ne.show(npdat, n)
    n = (n+1)%167
    _delay(100)
